
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <iostream>
#include <string>
//#include <md5c.h>
#include <stdio.h>
#include <sys/time.h>
#include "app_platform/cntl_info.h"
#include "app_platform/cgi_stub_cntl.h"
#include "../include/helloworlddao_stub4web_allinone.h"
#include "erp/helloworld/ddo/helloworldddo_helloworld.h"	
#include "erp/helloworld/ddo/helloworldfilterddo_helloworld.h"	
#include <set>	
#include <map>	

using namespace erp::helloworld::dao;

void Init()
{       
	if(CCGI_STUB_CNTL->Initialize(true) != 0)
		std::cerr << "CCGI_STUB_CNTL->Init failed" << std::endl;
	CCGI_STUB_CNTL->setTimeout(5);
}
void TestAddHelloWorld()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	erp::helloworld::ddo::CHelloWorldDdo helloWorld;
	std::string inReserve = "";		
	std::string errmsg = "";		
	erp::helloworld::ddo::CHelloWorldDdo helloWorldBack;
	std::string outReserve = "";		
	CHelloWorldDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.AddHelloWorld(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		helloWorld,
		inReserve,
		errmsg,
		helloWorldBack,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
void TestGetHelloWorldById()
{
	//TODO 如果使用配置中心来获取APP地址,请注释下行
	//CCGI_STUB_CNTL->setPeerAddr("172.25.34.123", 53101);

	//TODO 请设置用户Passport
	CCntlInfo oCntlInfo;
	oCntlInfo.setOperatorUin(88883687);
	oCntlInfo.setOperatorClientIP(0);
	oCntlInfo.setOperatorKey("stw3ymf9uk");
	//TODO 请设置路由值
	oCntlInfo.setRouteKey(88883687);
	std::string machineKey = "";		
	std::string source = "";		
	uint32_t sceneId = 0;
	erp::helloworld::ddo::CHelloWorldFilterDdo helloWorldFilter;
	std::string inReserve = "";		
	std::string errmsg = "";		
	std::map<uint32_t,erp::helloworld::ddo::CHelloWorldDdo > helloWorlds;
	std::string outReserve = "";		
	CHelloWorldDaoStub4Web oStub;
	// TODO:替换函数参数
    uint32_t dwResult = oStub.GetHelloWorldById(
		oCntlInfo,
		machineKey,
		source,
		sceneId,
		helloWorldFilter,
		inReserve,
		errmsg,
		helloWorlds,
		outReserve
  	);
    if(dwResult == 0)
	{
		std::cout << "Invoke OK!" << std::endl;
		printf("OK result[0x%x], time = %ld\n"
        , dwResult, oStub.GetLastConsumeTime());
	}
	else
    {
        printf("Error result[0x%x], time = %ld , errmsg = [%s]\n"
        , dwResult, oStub.GetLastConsumeTime(),oStub.GetLastErrMsg());
    }
}
//测试主函数
int main(int argc, char** argv)
{
	//
	//测试主流程
	// 开发人员可以根据业务需要进行顺序的调整，以期达到更好的测试效果
	// 比如，可以按照插入、选择、修改、选择、删除、选择 顺序进行处理
	//
	Init();
	TestAddHelloWorld();
	TestGetHelloWorldById();
	return 0;
}
